from copy import deepcopy

from pybloom_live import ScalableBloomFilter
d = ScalableBloomFilter()
d.add(321)
a  = {
    'per':{'count':312,'ss':d}
}
def serializable_bloom(result_dic):
    '''
    递归将bloom转换成int
    @param result_dic:dict
    @return:dict
    '''
    from models import Field
    new_result_dic = {}
    for k, v in result_dic.items():
        if isinstance(k, Field):
            k = k.name
        new_result_dic[k] = deepcopy(v)

    for k, v in new_result_dic.items():
        if isinstance(v, ScalableBloomFilter):
            new_result_dic[k] = new_result_dic[k].count
        if isinstance(v, dict):
            new_result_dic[k] = serializable_bloom(v)
    return new_result_dic
print(serializable_bloom(a))
